package com.magina.common.bean2xml;


import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JaxbDateStrAdapter extends XmlAdapter<Date, String> {
//    static final String STANDARM_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    static final String STANDARM_DATE_FORMAT = "yyyy-MM-dd";

    @Override
    public String unmarshal(Date v) throws Exception {
        if (v == null) {
            return null;
        }
        DateFormat format = new SimpleDateFormat(STANDARM_DATE_FORMAT);
        return format.format(v);
    }

    @Override
    public Date marshal(String v) throws Exception {
        DateFormat format = new SimpleDateFormat(STANDARM_DATE_FORMAT);
        return format.parse(v);
    }
}